package com.ztman.rxjava.view.activity;

import android.view.View;

import com.ztman.rxjava.R;
import com.ztman.rxjava.model.baseEntity.BaseResponse;
import com.ztman.rxjava.model.baseEntity.BaseRxBusEvent;
import com.ztman.rxjava.model.entityExtends.self.SelfInfo;
import com.ztman.rxjava.model.entityExtends.self.SelfModelIml;
import com.ztman.rxjava.mvp.presenter.ActivityPresenter;
import com.ztman.rxjava.mvp.viewProxy.SelfInfoActivityProxy;
import com.ztman.rxjava.server.retrofit.OnNetRequestListener;
import com.ztman.rxjava.utils.ToastPop;
/**
 * Created by YJH on 2017/11/30.
 * 功能：显示个人信息的 activity
 */
public class SelfInfoActivity extends ActivityPresenter<SelfInfoActivityProxy> implements View.OnClickListener{

    //网络数据请求分离的类
    private SelfModelIml mSelfModeIml;
    @Override
    protected Class<SelfInfoActivityProxy> getPresenterClass() {
        return SelfInfoActivityProxy.class;
    }

    @Override
    protected void initData() {
        mSelfModeIml = new SelfModelIml();
    }

    @Override
    protected void initView() {
        //设置控件的监听
        //atyPresenter 是 为SelfInfoActivity分离出去的逻辑操作功能
        atyPresenter.setOnClickListener(this, R.id.tSelf);
    }

    @Override
    protected void receiveRxBuxCommanders(BaseRxBusEvent baseRxBusEvent) {

    }

    @Override
    public void onClick(View v) {
        mSelfModeIml.setSelfParams(2, new OnNetRequestListener<BaseResponse<SelfInfo>>() {
            @Override
            public void onRequestStart() {
                ToastPop.showShort("个人信息请求开始..");
            }

            @Override
            public void onRequestFinish() {
                ToastPop.showShort("个人信息请求结束..");
            }

            @Override
            public void onRequestSuccess(BaseResponse<SelfInfo> data) {
                ToastPop.showShort("个人信息请求成功..");
                atyPresenter.setSelfInfo(data.data.getUserInfo().toString());
            }

            @Override
            public void onRequestFailure(Throwable t) {
                ToastPop.showShort("个人信息请求失败..");
            }
        });
    }
}
